import Vue from 'vue'
import Router from 'vue-router'
// 用户管理
import userList from '@/views/user/user-list'
import userLog from '@/views/user/user-log'
// 用户权限管理
import roleList from '@/views/role-permission-group/role-list'
import permissionGroupList from '@/views/role-permission-group/permission-group-list'
// 基础配置
import academyConfig from '@/views/config/academy-config'
import dormitoryConfig from '@/views/config/dormitory-config'
import professionConfig from '@/views/config/profession-config'
// 班级管理
import classRoomList from '@/views/classroom/classroom-list'
// 报到管理
import register from '@/views/register'
import finance from '@/views/finance'
// 住宿管理
import roomList from '@/views/room/room-list'
// 互动交流平台
import communicateList from '@/views/communicate/list'
import communicateDetail from '@/views/communicate/detail'
// 校园智能导览
import sceneList from '@/views/scene/list'
import sceneDist from '@/views/scene/distance'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/updatePassword',
    component: () => import ('@/views/user/update-password'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: '数据总览',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '数据总览', icon: 'dashboard' }
    }]
  },
  {
    path: '/user',
    component: Layout,
    meta: { title: '用户管理', icon: 'el-icon-s-help' },
    redirect: '/user/list',
    children: [
      {
        path: '/user/list',
        component: userList,
        meta: { title: '用户列表', icon: 'table' }
      },
      {
        path: '/user/log',
        component: userLog,
        meta: { title: '操作日志', icon: 'tree' }
      }
    ]
  },
  {
    path: '/role-permission-group',
    component: Layout,
    meta: { title: '用户权限管理', icon: 'el-icon-s-help' },
    redirect: '/role-permission-group/role-list',
    children: [
      {
        path: '/role-permission-group/role-list',
        component: roleList,
        meta: { title: '角色列表', icon: 'form' }
      },
      {
        path: '/role-permission-group/permission-group-list',
        component: permissionGroupList,
        meta: { title: '权限组列表', icon: 'form' }
      }
    ]
  },
  {
    path: '/config',
    component: Layout,
    meta: { title: '基础配置', icon: 'el-icon-s-help' },
    redirect: '/config/academy-config',
    children: [
      {
        path: '/config/academy-config',
        component: academyConfig,
        meta: { title: '学院配置', icon: 'form' }
      },
      {
        path: '/config/profession-config',
        component: professionConfig,
        meta: { title: '专业配置', icon: 'form' }
      },
      {
        path: '/config/dormitory-config',
        component: dormitoryConfig,
        meta: { title: '宿舍配置', icon: 'form' }
      }
    ]
  },
  {
    path: '/classroom',
    component: Layout,
    children: [
      {
        path: '/classroom',
        component: classRoomList,
        meta: { title: '班级管理', icon: 'form' }
      }
    ]
  },

  {
    path: '/register',
    component: Layout,
    meta: { title: '报到管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: '/register',
        component: register,
        meta: { title: '填写报到信息', icon: 'form' }
      },
      {
        path: '/finance',
        component: finance,
        meta: { title: '财务列表', icon: 'form' }
      }
    ]
  },
  {
    path: '/room',
    component: Layout,
    children: [
      {
        path: '/room-list',
        component: roomList,
        meta: { title: '住宿管理', icon: 'form' }
      }
    ]
  },
  {
    path: '/communicate',
    component: Layout,
    redirect: '/communicate/communicate-list',
    children: [
      {
        path: '/communicate/communicate-list',
        component: communicateList,
        meta: { title: '互动交流平台', icon: 'form' }
      }, {
        path: '/communicate/communicate-detail',
        component: communicateDetail,
        hidden: true,
        meta: { title: '帖子详情' }
      }
    ]
  },

  {
    path: '/scene',
    component: Layout,
    children: [
      {
        path: '/scene-list',
        component: sceneList,
        meta: { title: '校园智能导览', icon: 'form' }
      },
      {
        path: '/scene-distance',
        component: sceneDist,
        meta: { title: '场景距离列表', icon: 'form' },
        hidden: true
      }
    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', 设置路由模式，默认是 hash模式
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  // reset router 重置路由
  router.matcher = newRouter.matcher
}

export default router
